/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ie.tcd.cs.railtickets.server.dao.impl;

import ie.tcd.cs.railtickets.server.dao.RouteDAO;
import ie.tcd.cs.railtickets.server.domain.PathTime;
import ie.tcd.cs.railtickets.server.domain.Route;
import ie.tcd.cs.railtickets.server.domain.TravelPath;
import static ie.tcd.cs.railtickets.server.dao.impl.HibernateSessionFactory.getSession;

/**
 *
 * @author Wenbo Sun
 */
public class RouteDAOImpl extends AbstractBaseDAOImpl implements RouteDAO {

    public Route findByPath(TravelPath travelPath) {
        String query = "select travelPath.source.route from TravelPath travelPath where travelPath = ?";
        Route result = (Route) getSession().createQuery(query).setParameter(0, travelPath).iterate().next();
        return result;
    }

    public Route findByPathTime(PathTime pathTime) {
        String query = "select pathTime.routeTime.route from PathTime pathTime where pathTime = ?";
        Route result = (Route) getSession().createQuery(query).setParameter(0, pathTime).iterate().next();
        return result;
    }


}
